import { Module } from '@nestjs/common';
import { AuthService } from './auth.service';
import { AuthController } from './auth.controller';
import { UserModule } from '../user/user.module';
import { JwtModule } from '@nestjs/jwt';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { ConfigEnum } from '../enum/config.enum';
import { AuthGuard } from './auth.guard';
import { APP_GUARD } from '@nestjs/core';
import { CaslAbilityService } from './casl-ability.service';
import { CaslGuard } from '../guards/casl.guard';

@Module({
  imports: [
    UserModule,
    JwtModule.registerAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => ({
        global: true,
        secret: configService.get(ConfigEnum.JWT_SECRET),
        signOptions: { expiresIn: 24 * 60 * 60 + 's' },
      }),
      inject: [ConfigService],
    })
  ],
  providers: [
    AuthService,
    CaslAbilityService,
    {
      provide: APP_GUARD,
      useClass: AuthGuard,
    },
    {
      provide: APP_GUARD,
      useClass: CaslGuard,
    }
  ],
  controllers: [AuthController],
  exports: [AuthService, CaslAbilityService],
})
export class AuthModule {}
